﻿using System;
using System.Data;
using System.Data.SqlClient;

public class LoginAdminDAL
    {
        dbConnection db = new dbConnection();
        public  string CheckCredentials(LoginAdminBO AdminLogin)
        {
            SqlConnection cn = null;
            SqlCommand cmd = null;
            string Counter = "";

            dbConnection db = new dbConnection();
            
            try
            {
                cn = new SqlConnection();
                cn.ConnectionString = db.GetCS();

                cmd = new SqlCommand();
                cmd.Connection = cn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "Select Name  FROM Admin WHERE (USERNAME=@UserName) and Password=@Password  COLLATE SQL_Latin1_General_CP1_CS_AS";



                cmd.Parameters.AddWithValue("@UserName", AdminLogin.UserName);
                cmd.Parameters.AddWithValue("@Password", AdminLogin.Password);

                cn.Open();
                Counter = (string)(cmd.ExecuteScalar());

                //Counter = cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (cn != null)
                {
                    cn.Close();
                    cn.Dispose();
                    cn = null;
                }
            }
            return (Counter);
        }


        public  int UnSubscribeMe(LoginAdminBO AdminLogin)
        {
            SqlConnection cn = null;
            SqlCommand cmd = null;
            int Counter = 0;

            try
            {
                cn = new SqlConnection();
                cn.ConnectionString = db.GetCS();
                cmd = new SqlCommand();
                cmd.Connection = cn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Delete UserName from [Admin] where UserName=@UserName";

                cmd.Parameters.AddWithValue("@UserName", AdminLogin.UserName);


                cn.Open();
                Counter = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (cn != null)
                {
                    cn.Close();
                    cn.Dispose();
                    cn = null;
                }
            }
            return (Counter);
        }

    }

